﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using _619BJP.Models;
using System.Data.SqlClient;
using Microsoft.ApplicationBlocks.Data;
using System.Data;

namespace _619BJP.Database.Brand
{
    public class brandDB
    {
        private string connString = System.Configuration.ConfigurationManager.ConnectionStrings["619BJP.Data.ConnectionString"].ConnectionString;

        /// <summary>
        /// 得到所有品牌
        /// </summary>
        /// <returns></returns>
        public DataSet getAllBrands()
        {
            DataSet ds = new DataSet();
            string sql = "";
            using (SqlConnection conn = new SqlConnection(connString))
            {
                sql = "SELECT id,logo,name from BR_Brand ";
                ds = SqlHelper.ExecuteDataset(conn, CommandType.Text, sql);
            }
            return ds;
        }

        /// <summary>
        /// 品牌详情
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public BrandModel brandDetail(int id)
        {
            BrandModel brand = new BrandModel();
            using (SqlConnection conn = new SqlConnection(connString))
            {
                string sql = "SELECT * from BR_Brand where id = " + id;
                SqlDataReader sdr = SqlHelper.ExecuteReader(conn, CommandType.Text, sql);
                if (sdr.Read())
                {
                    brand.id = Convert.ToInt32(sdr["id"].ToString());
                    brand.name = sdr["name"].ToString();
                    brand.e_name = sdr["e_name"].ToString();
                    brand.logo = sdr["logo"].ToString();
                    brand.web_site = sdr["web_site"].ToString();
                    brand.description = sdr["description"].ToString();
                }
            }
            return brand;
        }

    }
}
